<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/base}">
<head>
    <title>我的农产品 - 暖心助农选品平台</title>
</head>
<body>
    <div layout:fragment="content">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2>我的农产品</h2>
            <a th:href="@{/farmer/products/new}" class="btn btn-primary">添加农产品</a>
        </div>
        
        <div th:if="${products.empty}" class="alert alert-info">
            您还没有添加任何农产品。
        </div>
        
        <div th:unless="${products.empty}" class="row row-cols-1 row-cols-md-3 g-4">
            <div class="col" th:each="product : ${products}">
                <div class="card h-100">
                    <img th:if="${product.image}" th:src="@{${product.image}}" class="card-img-top" alt="产品图片">
                    <img th:unless="${product.image}" th:src="@{/images/default-product.jpg}" class="card-img-top" alt="默认产品图片">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-start mb-2">
                            <h5 class="card-title mb-0" th:text="${product.name}">产品名称</h5>
                            <span class="badge" th:classappend="${product.approved ? 'bg-success' : 'bg-warning'}"
                                  th:text="${product.approved ? '已审核' : '待审核'}">状态</span>
                        </div>
                        <p class="card-text" th:text="${product.description}">产品描述</p>
                        <p class="card-text">
                            <small class="text-muted" th:text="'类别: ' + ${product.category}">类别</small>
                        </p>
                        <p class="card-text">
                            <strong class="text-danger" th:text="'￥' + ${product.price}">价格</strong>
                        </p>
                        <p class="card-text">
                            <small class="text-muted" th:text="'库存: ' + ${product.stock}">库存</small>
                        </p>
                        <div class="d-flex justify-content-between align-items-center mt-3">
                            <a th:href="@{/farmer/products/{id}/edit(id=${product.id})}" class="btn btn-primary btn-sm">
                                编辑
                            </a>
                            <form th:action="@{/farmer/products/{id}/delete(id=${product.id})}" method="post" 
                                  class="delete-form" onsubmit="return confirm('确定要删除这个农产品吗？');">
                                <button type="submit" class="btn btn-danger btn-sm">删除</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html> 